{640*480}

Program Coso;

USES Draw,Mouse,Tools,Buffer,Menu;

var
i,n: Integer;
plick:Integer;
plicki:Integer; {El estado anterior del mouse}
keyRead:Byte;
click:boolean;
{Coordenadas actuales del mouse}
x,y:Integer;
xi,yi:Integer;

drawObj:TDraw;
mouseObj:TMouse;
tool:TTools;
buff:TBuffer;
menuObj:TMenu;

{para lìnea}
x0,y0:Integer;
xo,yo:Integer;
fin:boolean;
numLineas:integer;
prevtool,actualTool:integer;

CONST color0=0;color1=1;color2=2;color3=3;
	color4=4;color5=5;color6=6;color7=7;
	color8=8;color9=9;color10=10;color11=11;
	color12=12;color13=13;color14=14;color15=15;

	{Herramientas}
	eraser=16;fill=17;pick=18; select=19;
	pencil=20;broch=21;spray=22;text=23;
	line=24;circle=25;rectangle=26;poligon=27;
	
	
    {
	 setVideo:
	 Pasar a modo video
	}
	procedure setVideo;
	BEGIN
		ASM
			MOV AX, 12H
			INT 10H
		end;

	END;

	{
	 unsetVideo:
	 Salir de modo video
	}
	procedure unsetVideo;
	BEGIN
		ASM
			MOV AX, 1100h
			INT 10H
		end;

	END;
	

		
	{Esperar una tecla}
	procedure getKey;
	BEGIN
		ASM
		MOV AH,00H
		INT 16H
		MOV [keyRead],AL
		END;
		{write(keyRead);}
	END;
		

{Main }	

begin
	{botones de colores}
	

	buff.initBuffer;
	tool.setObjects(mouseObj,drawObj,bufferObj,menuObj);
	setVideo;
	mouseObj.reset;
		
	menuObj.setMenu(drawObj,639,479);
	menuObj.show;
	menuObj.canvasnew;
	mouseObj.show;
	drawObj.setFree(false);
	
	mouseObj.getXY(x,y);
	actualTool:=pencil;
	
	{Ciclo, mientras no se presione clic izquierdo y derecho juntos}
	WHILE mouseObj.getStatus<>3 DO
		BEGIN
			mouseObj.getXY(x,y);
			
			IF mouseObj.clicked(plicki,plick) then	
			Begin
				mouseObj.getXY(x,y);	
				prevTool:=actualTool;
				actualTool:=menuObj.getTool(x,y);
			end;	
			
				if (actualTool<16)AND (actualTool>=0) then
					begin
						tool.setColor(actualTool);
						
						actualTool:=prevTool;
					end;
				
				
				
				case actualTool of
					{Herramientas}
					eraser:tool.eraser(xi,yi,x,y,9);
					fill:write(' No hay fill');
					pick:write(' pick ');
					select:write('select');
					broch:tool.broch(xi,yi,x,y,9);
					pencil:tool.pencil(xi,yi,x,y);
					spray:tool.spray(xi,yi,x,y,9);
					text: write( ' nuai text ');
					line: tool.line(xi,yi,x,y);
					circle: tool.ellipse(xi,yi,x,y);
					rectangle:tool.rectangle(xi,yi,x,y);
					poligon: write('No hay poligono');
				end;			
			
	END;
	readln(n);
end.

